package com.bafa.objects;

import java.io.Serializable;
import java.util.HashMap;
import java.util.StringTokenizer;

import com.bafa.objects.schema.ObjectFactory;

public class TeamDetails implements Serializable{

	private String Name         =""  ;         
	private String ContactName1   ="";         
	private String ContactEmail1  ="";         
	private String ContactTel1    ="";         
	private String ShirtColour ="";
	private HashMap missingFields = new HashMap();
	
	private double moneyOwed;
	private boolean paymentRequired;
	
	public com.bafa.objects.schema.TeamDetails mapTo(){
		ObjectFactory factory = new ObjectFactory();
		com.bafa.objects.schema.TeamDetails details = factory.createTeamDetails();
		
		details.setName(getName());
		details.setContactEmail1(getContactEmail1());
		details.setContactEmail2(getContactEmail2());
		details.setContactName1(getContactName1());
		details.setContactName2(getContactName2());
		details.setContactTel1(getContactTel1());
		details.setContactTel2(getContactTel2());
		details.setHomeShirtColour(getShirtColour());
		
		
		return details;
	}
	public TeamDetails(com.bafa.objects.schema.TeamDetails teamDetails){
		this(
				teamDetails.getName(),
				teamDetails.getContactName1(),
				teamDetails.getContactName2(),
				teamDetails.getContactEmail1(),
				teamDetails.getContactEmail2(),
				teamDetails.getContactTel1(),
				teamDetails.getContactTel2(),
				teamDetails.getHomeShirtColour(),
				teamDetails.getPaymentRequired());
	}
	public TeamDetails(
			 String Name   ,
			 String ContactName1   ,         
			 String ContactName2   ,         
			 String ContactEmail1  ,         
			 String ContactEmail2  ,         
			 String ContactTel1    ,         
			 String ContactTel2    ,         
			 String ShirtColour,
			 double moneyOwed){
				 this.Name   = Name ;
				 this.ContactName1   = ContactName1 +":"+ ContactName2;         
				 this.ContactEmail1  = ContactEmail1 +":"+ ContactEmail2; 
				 this.ContactTel1    = ContactTel1+":"+ContactTel2;      
				 if(ShirtColour!=null)this.ShirtColour = ShirtColour;
				 this.moneyOwed = moneyOwed;
				 if(moneyOwed>0.00) paymentRequired=true;
				 else paymentRequired=false;
				 setMissingFields();
				 
			}

	public String getContactEmail1() {
		StringTokenizer st = new StringTokenizer(ContactEmail1,":");
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		
		return email1;
	}

	public String getContactEmail2() {
		StringTokenizer st = new StringTokenizer(ContactEmail1,":");
		if(st.hasMoreTokens())st.nextToken();
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		return email1;
	}

	public String getContactName1() {
		StringTokenizer st = new StringTokenizer(ContactName1,":");
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		return email1;
	}

	public String getContactName2() {
		StringTokenizer st = new StringTokenizer(ContactName1,":");
		if(st.hasMoreTokens())st.nextToken();
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		return email1;
	}

	public String getContactTel1() {
		StringTokenizer st = new StringTokenizer(ContactTel1,":");
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		return email1;
	}

	public String getContactTel2() {
		StringTokenizer st = new StringTokenizer(ContactTel1,":");
		if(st.hasMoreTokens())st.nextToken();
		String email1 = "";
		if(st.hasMoreTokens())email1 =st.nextToken();
		return email1;
	}

	

	public HashMap getMissingFields() {
		return missingFields;
	}

	public double getMoneyOwed() {
		return moneyOwed;
	}

	public String getName() {
		return Name;
	}

	

	public boolean isPaymentRequired() {
		return paymentRequired;
	}

	public String getShirtColour() {
		return ShirtColour;
	}
	
	private void setMissingFields(){
		if(ContactEmail1.equals(""))missingFields.put("contactEmail1","First Contact Email");
		else if(ContactEmail1.indexOf("@")==-1)missingFields.put("contactEmail1", "First Contact Email");
		if(getContactEmail2().equals(""))missingFields.put("contactEmail2", "Second Contact Email");
		else if(getContactEmail2().indexOf("@")==-1)missingFields.put("contactEmail2","Second Contact Email");
		if(ContactTel1.equals(""))missingFields.put("contactTel1","First Contact Telephone");
		if(getContactTel2().equals(""))missingFields.put("contactTel2", "Second Contact Telephone");
		if(getContactName2().equals(""))missingFields.put("contactName2","Second Contact");
	}
	
	public String[] missingFieldKeys(){
		return (String[])missingFields.keySet().toArray(new String[missingFields.size()]);
		
	}
	
	public String[] missingFieldValues(){
		return (String[])missingFields.values().toArray(new String[missingFields.size()]);
		
	}
	
}
